package app

import (
	"github.com/gin-gonic/gin"
	"user-web/src/controller"
	"user-web/src/middleware"

	"github.com/gin-contrib/pprof"
)

func InitGin() {
	engine := gin.Default()

	//性能分析
	pprof.Register(engine)

	//使用中间件
	//engine.Use(middleware.Cors())
	engine.Use(middleware.AuthRequired())

	//图片上传
	// (默认是 32 MiB)
	engine.MaxMultipartMemory = 8 << 20 // 8 MiB

	initRouter(engine)

	// By default it serves on :8080 unless a
	// PORT environment variable was defined.
	if err := engine.Run(); err != nil {
		panic(err)
	}
}

func initRouter(engine *gin.Engine) {
	new(controller.UserController).RegisterRouter(engine)
}
